#!/usr/bin/env bun

import PptxGenJs from 'pptxgenjs';

async function testAdvancedFeatures() {
  console.log('🎨 高级PPT功能测试：渐变、透明度、图形元素...');
  
  try {
    const ppt = new PptxGenJs();
    ppt.layout = 'LAYOUT_WIDE';
    ppt.author = '张三';
    ppt.title = '高级PPT功能演示';
    
    // 1. 渐变背景测试
    console.log('测试1: 渐变背景...');
    const slide1 = ppt.addSlide();
    // 注意：PPTXGenJS可能不直接支持渐变背景，但可以用形状实现
    slide1.addShape((ppt as any).shapes.RECTANGLE, {
      x: 0, y: 0, w: 10, h: 5.625,
      fill: { 
        color: '2c3e50',
        transparency: 0 
      },
      line: { width: 0 }
    });
    
    // 添加渐变效果的形状
    slide1.addShape((ppt as any).shapes.RECTANGLE, {
      x: 0, y: 0, w: 10, h: 2.8,
      fill: { 
        color: '3498db',
        transparency: 70 
      },
      line: { width: 0 }
    });
    
    slide1.addText('渐变背景效果测试', {
      x: 1, y: 2, w: 8, h: 1,
      fontSize: 32, color: 'ffffff', bold: true,
      align: 'center'
    });
    
    // 2. 透明度测试
    console.log('测试2: 透明度效果...');
    const slide2 = ppt.addSlide();
    slide2.background = { color: '2c3e50' };
    
    // 不同透明度的矩形
    const transparencies = [0, 25, 50, 75, 90];
    transparencies.forEach((trans, index) => {
      slide2.addShape((ppt as any).shapes.RECTANGLE, {
        x: 0.5 + index * 1.8, 
        y: 1.5, 
        w: 1.5, 
        h: 2.5,
        fill: { 
          color: '3498db',
          transparency: trans 
        },
        line: { color: 'ffffff', width: 1 }
      });
      
      slide2.addText(`${trans}%`, {
        x: 0.5 + index * 1.8, 
        y: 4.2, 
        w: 1.5, 
        h: 0.5,
        fontSize: 14, color: 'ffffff', bold: true,
        align: 'center'
      });
    });
    
    slide2.addText('透明度效果对比', {
      x: 1, y: 0.5, w: 8, h: 0.8,
      fontSize: 28, color: 'ffffff', bold: true,
      align: 'center'
    });
    
    // 3. 图形元素组合测试
    console.log('测试3: 图形元素组合...');
    const slide3 = ppt.addSlide();
    slide3.background = { color: '34495e' };
    
    // 圆形
    slide3.addShape((ppt as any).shapes.OVAL, {
      x: 1, y: 1.5, w: 2, h: 2,
      fill: { color: 'e74c3c', transparency: 20 },
      line: { color: 'ffffff', width: 2 }
    });
    
    // 三角形 (使用正确的API名称)
    slide3.addShape((ppt as any).shapes.ISOSCELES_TRIANGLE, {
      x: 4, y: 1.5, w: 2, h: 2,
      fill: { color: '2ecc71', transparency: 30 },
      line: { color: 'ffffff', width: 2 }
    });
    
    // 六边形
    slide3.addShape((ppt as any).shapes.HEXAGON, {
      x: 7, y: 1.5, w: 2, h: 2,
      fill: { color: 'f39c12', transparency: 25 },
      line: { color: 'ffffff', width: 2 }
    });
    
    slide3.addText('图形元素组合', {
      x: 1, y: 4, w: 8, h: 1,
      fontSize: 24, color: 'ffffff', bold: true,
      align: 'center'
    });
    
    // 4. 科技风装饰元素
    console.log('测试4: 科技风装饰元素...');
    const slide4 = ppt.addSlide();
    slide4.background = { color: '1a1a2e' };
    
    // 标题区域装饰
    slide4.addShape((ppt as any).shapes.RECTANGLE, {
      x: 0, y: 0, w: 10, h: 1.5,
      fill: { color: '3498db', transparency: 80 },
      line: { width: 0 }
    });
    
    // 左侧装饰线
    slide4.addShape((ppt as any).shapes.RECTANGLE, {
      x: 0, y: 0, w: 0.1, h: 5.625,
      fill: { color: '00d4ff', transparency: 0 },
      line: { width: 0 }
    });
    
    // 右下角装饰
    slide4.addShape((ppt as any).shapes.RECTANGLE, {
      x: 8, y: 4.5, w: 2, h: 1.125,
      fill: { color: '16537e', transparency: 50 },
      line: { width: 0 }
    });
    
    // 中心内容区域
    slide4.addShape((ppt as any).shapes.RECTANGLE, {
      x: 1, y: 2, w: 8, h: 2,
      fill: { color: '2c3e50', transparency: 20 },
      line: { color: '00d4ff', width: 1 }
    });
    
    slide4.addText('科技风年终述职报告', {
      x: 1, y: 0.3, w: 8, h: 0.8,
      fontSize: 32, color: 'ffffff', bold: true,
      align: 'center'
    });
    
    slide4.addText('Technical Annual Report', {
      x: 1.5, y: 2.5, w: 7, h: 1,
      fontSize: 24, color: '00d4ff', bold: false,
      align: 'center'
    });
    
    // 5. 数据可视化风格
    console.log('测试5: 数据可视化风格...');
    const slide5 = ppt.addSlide();
    slide5.background = { color: '2c3e50' };
    
    // 模拟图表背景
    slide5.addShape((ppt as any).shapes.RECTANGLE, {
      x: 1, y: 1, w: 8, h: 4,
      fill: { color: '34495e', transparency: 30 },
      line: { color: '3498db', width: 1 }
    });
    
    // 模拟数据条
    const dataValues = [80, 65, 90, 45, 75];
    const colors = ['e74c3c', '2ecc71', 'f39c12', '9b59b6', '1abc9c'];
    
    dataValues.forEach((value, index) => {
      const height = (value / 100) * 2.5;
      slide5.addShape((ppt as any).shapes.RECTANGLE, {
        x: 2 + index * 1.2, 
        y: 3.5 - height, 
        w: 0.8, 
        h: height,
        fill: { color: colors[index], transparency: 20 },
        line: { color: colors[index], width: 1 }
      });
      
      // 数据标签
      slide5.addText(`${value}%`, {
        x: 2 + index * 1.2, 
        y: 3.8, 
        w: 0.8, 
        h: 0.3,
        fontSize: 12, color: 'ffffff', bold: true,
        align: 'center'
      });
    });
    
    slide5.addText('数据可视化风格示例', {
      x: 1, y: 0.3, w: 8, h: 0.8,
      fontSize: 28, color: 'ffffff', bold: true,
      align: 'center'
    });
    
    const outputPath = '/Users/ahata/Downloads/advanced-features-test.pptx';
    console.log(`💾 保存到: ${outputPath}`);
    
    await new Promise((resolve, reject) => {
      ppt.writeFile({ fileName: outputPath })
        .then(() => {
          console.log('✅ 高级功能测试完成！');
          console.log('\n🎯 测试包含:');
          console.log('   1. 渐变背景效果（通过透明图层实现）');
          console.log('   2. 透明度对比展示（0%-90%）');
          console.log('   3. 图形元素组合（圆形、三角形、六边形）');
          console.log('   4. 科技风装饰元素');
          console.log('   5. 数据可视化风格');
          console.log('\n💡 可以将这些技术应用到年终述职模板中！');
          resolve(void 0);
        })
        .catch(reject);
    });
    
  } catch (error) {
    console.error('❌ 高级功能测试失败:', error);
  }
}

if (import.meta.main) {
  testAdvancedFeatures();
}
